<?php 
ob_flush();
ob_start();

header("Expires: Mon, 26 Jul 1970 05:00:00 GMT");      
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");      
header("Cache-Control: no-cache, must-revalidate");      
header("Pragma: no-cache"); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
/* <![CDATA[ */

table, td
{
    border-color: #666;
    border-style: solid;
}
table, th
{
    border-color: #666;
    border-style: solid;
}

table
{
    border-width: 0 0 1px 1px;
    border-spacing: 0;
    border-collapse: collapse;
}
 
td
{
    margin: 0;
    padding: 4px;
    border-width: 1px 1px 0 0;
}
th
{
    margin: 0;
    padding: 4px;
    border-width: 1px 1px 0 0;
}

/* ]]> */
</style>

<!--SCRIPTSTART-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script language="javascript" >

$(document).ready(function() {
$('#form1').bind("keyup keypress", function(e) {
  var code = e.keyCode || e.which; 
  if (code  == 13) {               
    e.preventDefault();
	$('#input_qty_show').focus();
	$('#input_qty_show').select();
	
    return false;
  }  
  if (code  == 17) { 	                
    e.preventDefault();
    $('#form1').submit();
  }  
});
});

</script>
<script language="javascript">

function getfocus(){
	document.getElementById('input_field').select();
	document.getElementById('input_field').focus();
	document.getElementById('input_field').value = "";
	}

</script>
<!--SCRIPTEND-->
</head>
<body style="font-family:Arial, Helvetica, sans-serif;" onload="getfocus()">
<form method="post" id="form1" >
<h1>Online Order Counter<br />
  <?php echo $this->noOrder; ?> | 
  <br />
</h1>
<h2>[Auto Save Function Enabled]<br />
</h2>
<table width="800" border="1" cellspacing="0" cellpadding="10">
  <tr>
    <th scope="col" width="200" >Un-Counted / Not Sent</th>
    <th scope="col" width="200" style="background-color:#09F;" >Extra</th>
    <th scope="col" width="200"  style="background-color:#FC0;" >Less</th>
    <th scope="col" width="200" style="background-color:#090;" >Correct</th>
  </tr>
  <tr>
    <td align="center" valign="middle"><?php echo count($this->arrUnCount); ?></td>
    <td align="center" valign="middle" style="background-color:#C4DEFB" ><?php echo count($this->arrExtra); ?></td>
    <td align="center" valign="middle"  style="background-color:#FFFFB0"><?php echo count($this->arrShort); ?></td>
    <td align="center" valign="middle" style="background-color:#C8FF9F"><?php echo count($this->arrCorrect); ?></td>
  </tr>
</table>
<p>&nbsp;</p>
<table width="800" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td style="width:150px;">Scanning:</td>
    <td><b><?php

	if($_POST && !isset($_POST["btn_cancel"])){

		$barCode = trim($this->inputBarcode);
		$qty = trim($this->inputQty);	
		echo $barCode." x [".$qty."] pieces";
		}
	else{
		echo "Product Name x[0] pieces";	
	}	
    
	?></b></td>
  </tr>
  <tr>
    <td align="right"><img src="/images/bcode.jpg"  height="60" /></td>
    <td>
    <input name="input_barcode" type="hidden" value="<?php echo $this->inputBarcode;?>" />
    <input name="input_qty" type="hidden" value="<?php echo $this->inputQty;?>" />
    <input type="text" name="input_field" id="input_field" style="font-size:36px; width:320px;" value="<?php echo trim($this->inputBarcode);?>"  />
    <span style="font-size:36px;"  > x </span> <input name="input_qty_show" type="text" id="input_qty_show" style="font-size:36px; width:80px;" value="1"  />
    <span style="font-size:28px;"  > Pcs </span>
    <input type="submit" name="btn_input_text" id="btn_input_text" value="Press 'Ctrl' Key To Continue" style="font-size:36px; background-color:#080;" /></td>
  </tr>
  <tr>
    <td colspan="2" valign="top"> <p>Scan Barcode and Input Qty</p>
      <p>You can Input Negative Number</p></td>
    </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<br />


<h3 style="background-color:#09F;">Found Extra  Than Order</h3>
<table width="800" border="1" cellspacing="0" cellpadding="0" style="background-color:#C4DEFB;font-size:12px;">
  <tr>
    <td style="width:150px;">Barcode</td>
    <td  style="width:500px;">Product</td>
    <td>Order</td>
    <td>Sent</td>
    <td>Diff</td>
    </tr>
 <?php foreach($this->arrExtra as $k0 => $v){?> 
  <tr>
    <td <?php if($v[2] == 0){echo ' bgcolor="#8080FF"';}?> ><?php echo $v[0]?></td>
    <td <?php if($v[2] == 0){echo ' bgcolor="#8080FF"';}?> ><?php echo $v[1]?></td>
    <td <?php if($v[2] == 0){echo ' bgcolor="#8080FF"';}?> ><?php echo $v[2]?></td>
    <td <?php if($v[2] == 0){echo ' bgcolor="#8080FF"';}?> ><?php echo $v[3]?></td>
    <td <?php if($v[2] == 0){echo ' bgcolor="#8080FF"';}?> ><?php echo (($v[3] - $v[2])>0)?"+":""?><?php echo $v[3] - $v[2]?></td>
    </tr>
 <?php }?> 
</table>

<h3 style="background-color:#FC0;">Found Less Than Order </h3>
<table width="800" border="1" cellspacing="0" cellpadding="0" style="background-color:#FFFFB0;font-size:12px;">
  <tr>
    <td style="width:150px;">Barcode</td>
    <td  style="width:500px;">Product</td>
    <td>Order</td>
    <td>Sent</td>
    <td>Diff</td>
    <td>&nbsp;</td>
  </tr>
 <?php foreach($this->arrShort as $k0 => $v){?> 
  <tr>
    <td><?php echo $v[0]?></td>
    <td><?php echo $v[1]?></td>
    <td><?php echo $v[2]?></td>
    <td><?php echo $v[3]?></td>
    <td><?php echo (($v[3] - $v[2])>0)?"+":""?><?php echo $v[3] - $v[2]?></td>
    <td>&nbsp;</td>
  </tr>
 <?php }?> 
</table>



<h3 style="background-color:#CCC;">Un-Counted / Un-Found Barcode </h3>

<table width="800" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;">
  <tr>
    <td style="width:150px;">Barcode</td>
    <td  style="width:500px;">Product</td>
    <td>Order</td>
    <td>Sent</td>
    <td>Diff</td>
    </tr>
 <?php foreach($this->arrUnCount as $k0 => $v){?> 
  <tr>
    <td><?php echo $v[0]?></td>
    <td><?php echo $v[1]?></td>
    <td><?php echo $v[2]?></td>
    <td><?php echo $v[3]?></td>
    <td><?php echo (($v[3] - $v[2])>0)?"+":""?><?php echo $v[3] - $v[2]?></td>
    </tr>
 <?php }?> 
</table>


<h3 style="background-color:#090;">Found Quantity is  Correct  </h3> 
<table width="800" border="1" cellspacing="0" cellpadding="0" style="font-size:12px;background-color:#C8FF9F">
  <tr>
    <td style="width:150px;">Barcode</td>
    <td  style="width:500px;">Product</td>
    <td>Order</td>
    <td>Sent</td>
    <td>Diff</td>
    <td>&nbsp;</td>
  </tr>
 <?php foreach($this->arrCorrect as $k0 => $v){?> 
  <tr>
    <td><?php echo $v[0]?></td>
    <td><?php echo $v[1]?></td>
    <td><?php echo $v[2]?></td>
    <td><?php echo $v[3]?></td>
    <td><?php echo (($v[3] - $v[2])>0)?"+":""?><?php echo $v[3] - $v[2]?></td>
    <td>&nbsp;</td>
  </tr>
 <?php }?> 
</table>
</form>
<?php if(!isset($_GET['email'])){?>
<a href="<?php echo $_SERVER['REQUEST_URI'] ?>?email=yes "><h1>I have Finished The Scanning,Send Email To Shop </h1></a>
<?php }?>
<h1><a href="http://<?php echo SERVER_IP_COMM;?>/products/generate-kt/orderno/<?php echo $this->noOrder; ?>" target="_blank">EXPORT KT</a></h1>

</body>

</html>
<?php
$mailbody = ob_get_contents();

$mailbody = str_replace("Un-Counted / Un-Found Barcode","Did Not Sent To You",$mailbody);
$mailbody = str_replace("Online Order Counter","Monday Delivery List (May Not Be The Final Order)",$mailbody);

$posBegin = strpos($mailbody,"<!--SCRIPTSTART-->");
$posEnd = strpos($mailbody,"<!--SCRIPTEND-->");
$mailbody1 = substr($mailbody,0,$posBegin);
$mailbody2 = substr($mailbody,$posEnd);
$mailbody = $mailbody1.$mailbody2; 



if(isset($_GET['email'])){
	
	$mail = new Model_Emailshandler();
	$mail->sendNormalEmail($this->shopEmail,"Your Delivery This Week",$mailbody);

	}
?>